﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Vision.Common
{
    //点
    public class CDrawPoint : CDrawObj
    {
        //private PointF pt = new PointF();
        private readonly float PointLen = 5;
        public PointF Pt { get; set; } = default;

        static Pen BorderPen { get; set; } = new Pen(Color.Red);//边框颜色
        static Pen BorderPenSelected { get; set; } = new Pen(Color.Green,2);//边框颜色
        public CDrawPoint(PointF pt=default)
        {
            this.Pt = pt;
        }

        //绘制
        public override void Draw(Graphics g, float scale = 1)
        {
            if (m_visible == false)
                return;
            if (scale > 1)
                scale = 1;
            float crossWidth = PointLen / scale;
            Pen curPen=State == TrackerState.normal ? BorderPen: BorderPenSelected;
            
            g.DrawLine(curPen, Pt.X - crossWidth, Pt.Y - crossWidth, Pt.X + crossWidth, Pt.Y + crossWidth);
            g.DrawLine(curPen, Pt.X - crossWidth, Pt.Y + crossWidth, Pt.X + crossWidth, Pt.Y - crossWidth);
            g.DrawEllipse(curPen, Pt.X - crossWidth-1, Pt.Y - crossWidth-1, crossWidth * 2+2, crossWidth * 2+2);
        }

        public override TrackerInfo GetTrack(PointF pt, float scale)
        {
            if (scale > 1)
                scale = 1;
            float crossWidth = PointLen / scale;
            bool bIn = IntersectsWith(pt.X, pt.Y, Pt.X - crossWidth, Pt.X + crossWidth, Pt.Y - crossWidth, Pt.Y + crossWidth);
            return new TrackerInfo() 
            { 
                pos = bIn?TrackerPos.tIn:TrackerPos.tOut, 
                para = 0 
            };
        }

        public new CDrawPoint Copy()
        {
            CDrawPoint obj = new CDrawPoint();
            CopyTo(obj);
            return obj;
        }
        public void CopyTo(CDrawPoint node)
        {
            base.CopyTo(node);
            node.Pt = Pt;
        }
    }
}
